package com.gams.springboot.dao;

import com.gams.springboot.pojo.Role;
import com.gams.springboot.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


import java.util.List;

/**
 * @author tql
 * @current springboot
 * @create 2021-09-9-10:11
 */
public interface RoleDao {
    //查询所有角色
    @Select("select * from sys_role")
    List<Role> SelectAllRole();

    //新增角色
    @Insert("insert into sys_role(name," +
            "status,createTime,updateTime)values(#{name},#{status},#{createTime},#{updateTime});")
    int addRole(Role role);

    //修改角色
    @Update("update sys_role set name=#{name},status=#{status},updateTime=#{updateTime} where id=#{id}")
    int updateRole(Role user);

    //删除角色
    @Delete("delete from sys_role where id=#{id} ")
    int deleteRole(long id);

    //根据id删除菜单角色关联
    @Delete("delete from role_menu where roleId=#{roleId}")
    int deleteRoleMenu(long id);

    //根据菜单名查找id
    @Select("select id from sys_role where name = #{name}")
    int queryId(String name);

    //新增菜单角色关联
    @Insert("insert into role_menu(menuId,roleId)values (#{menuId},#{roleId})")
    int insertMenuRole(long menuId,long roleId);

    //查询用户角色关联表
    @Select("select roleId from user_role where userId = #{userId}")
    List<Role> selectRoleIdList(long userId);

    List<Role> selectAllRoleByUserId(long userId);
}
